package org.kl.auditsupervision.service.fnd;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.kl.auditsupervision.entity.fnd.AuditDefect;
import org.kl.auditsupervision.entity.fnd.EffectEvaluate;
import org.kl.auditsupervision.repository.fnd.AuditDefectDao;
import org.kl.bf.service.BasicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;


/**
 * 
 * 审计缺陷表
 * @author LJ
 *
 */
@Component
//默认将类中的所有public函数纳入事务管理.
@Transactional
public class AuditDefectService extends BasicService<AuditDefect>
{
  @Autowired
  private AuditDefectDao auditDefectDao;
  
  public List<AuditDefect> findByAuditProDtlIdAndStatus(String auditproId,String stutas){
	  return auditDefectDao.findByAuditProDtlIdAndStatus(auditproId,stutas);
  };
  
  public List<AuditDefect> findByAuditProDtlIdOrderByYearDesc(String auditproId){
	  return auditDefectDao.findByAuditProDtlIdOrderByYearDesc(auditproId);
  };
  
  public String multiDelete(String ids) {
		String[] idArray = StringUtils.split(ids, ",");
		int i = 0,j=0;
		for (String id : idArray) {
			if (StringUtils.isNotBlank(id)) {
				AuditDefect entity = basicDao.findOne(id);
				if(entity.getStatus()==null||!entity.getStatus().equals("1")){
					basicDao.delete(id);
					i++;
				}else{
					j++;
				}
			}
		}
		return "成功删除" + i + "条记录,忽略" + j + "条已审批记录";
	}
}
